package com.reins.bookstore.controller;

import com.reins.bookstore.entity.Basketline;
import com.reins.bookstore.object.BasketlineDTO;
import com.reins.bookstore.object.OneBookOrder;
import com.reins.bookstore.service.BasketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

@RestController
public class BasketController {

    @Autowired
    private BasketService basketService;


    @RequestMapping("/findAllBasketlines")
    public List<Basketline> findAllBuylists() {
        return basketService.findAllBuylists();
    }

    @RequestMapping("/findBuylistById")
    public Basketline findBuylistById(@RequestParam("id") Integer id) {

        return basketService.findBuylistById(id);
    }

    @RequestMapping("/findAllBasketlinesByUserId")
    public List<BasketlineDTO> findAllBuylistsByUserId(@RequestParam("id") Integer id) {
        List<BasketlineDTO> res = new LinkedList<>();

        try {
            res = basketService.findAllBasketlinesByUserId(id);
        } catch (Exception ex) {
            return null;
        }
        return res;
    }


    @RequestMapping("/saveOneBasketline")
    public BasketlineDTO saveOneBasketLine(@RequestBody OneBookOrder params) {
        BasketlineDTO res;
        try {
            res = basketService.saveOneBasketline(params);
        } catch (Exception ex) {
            return null;
        }
        return res;
    }


    @RequestMapping("/deleteOneBasketline")
    public Integer deleteBuylistById(@RequestBody OneBookOrder params) {
        Integer res;
        try {
            res = basketService.deleteOneBasketline(params);
        } catch (Exception ex) {
            return null;
        }
        return res;
    }
}
